package com.sam.im.heiqun.uis.activities;

import android.content.Intent;
import android.os.Bundle;
import android.text.InputFilter;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.sam.im.heiqun.R;
import com.yuyh.library.uis.activitys.BaseActivity;

import butterknife.BindView;
import butterknife.OnClick;


/**
 * 需要传入两个值，
 *      title   - - - -  title
 *      hint  - - - - -  提示语
 *
 *   返回值 字段 ：
 *          resultStr
 */
public class AlterNickSign extends BaseActivity {

    @BindView(R.id.center_title)
    TextView title;
    @BindView(R.id.right_commit)
    TextView commit;

    @BindView(R.id.alter_edit)
    EditText alterEdit;

    @BindView(R.id.left_back)
    ImageView back;

    private String titleStr;
    private String hintStr;
    private int state;
    private String contenttext  = null ;
    @Override
    public int getContentViewId() {
        return R.layout.activity_alter_nick;
    }

    @Override
    public void init(Bundle savedInstanceState) {

        titleStr = getIntent().getStringExtra("title");
        hintStr = getIntent().getStringExtra("hint");
        state = getIntent().getIntExtra("state",0);
        contenttext = getIntent().getStringExtra("data");
        if (titleStr.equals("")||titleStr==null){
        }else {
            title.setText(titleStr);
        }
        if (hintStr.equals("")||hintStr==null){
        }else {
            alterEdit.setHint(hintStr);
        }
        if (contenttext != null) {
            alterEdit.setText(contenttext);
        }
        if (state == PersonalInformationActivity.REQUEST_NICK){
            alterEdit.setFilters(new InputFilter[]{new InputFilter.LengthFilter(10)}); //最大输入长度
        }else if (state == PersonalInformationActivity.REQUEST_SIGN)
        {
            alterEdit.setFilters(new InputFilter[]{new InputFilter.LengthFilter(50)}); //最大输入长度
        }
    }

    @OnClick({R.id.left_back, R.id.right_commit})
    public void onClick(View view) {
        String str = alterEdit.getText().toString();
        Intent data = new Intent();
        switch (view.getId()) {
            case R.id.right_commit:
                if (null==str||"".equals(str)){
                    showToast(getResources().getString(R.string.not_null));
                }else{
                    //做提交
                    data.putExtra("resultStr", str);
                    setResult(RESULT_OK, data);
                    finish();
                }

                break;
            case R.id.left_back:
                setResult(RESULT_CANCELED);
                finish();
                break;
        }
    }
}
